package com.oa.jixiao.controller;

import java.time.LocalDateTime;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oa.jixiao.biz.AttendanceBiz;
import com.oa.jixiao.entity.Attendance;

@Controller
@RequestMapping("/jixiao")
public class AttendanceController {
	@Resource
	private AttendanceBiz atdBiz;
	
	@RequestMapping("/daka")
	public String daka(){
		return "/jixiao/daka";
	}
	
	@ResponseBody
	@RequestMapping("/hello")
	public int hello(Attendance record){
		record.setAtdDate(LocalDateTime.now().toString().substring(0,10));
		int row=atdBiz.find(record);
//		System.out.println(row);
		if(row==0){
			//  1 代表未打卡
			return  1;
		}else{
			//  -1代表已打卡
			return -1;
		}
		
	}
	
	@ResponseBody
	@RequestMapping("/am")
	public int record(Attendance record){
			record.setAtdDate(LocalDateTime.now().toString().substring(0,10));
			int row=atdBiz.find(record);
			if(row==0){
				record.setAtdAm(LocalDateTime.now().toString().substring(11,19));
				int rows=atdBiz.insert(record);
				return rows;
			}else{
				return -1;
			}
	}
	
	@ResponseBody
	@RequestMapping("/pm")
	public int daka(Attendance record){
		record.setAtdDate(LocalDateTime.now().toString().substring(0,10));
		int row=atdBiz.find(record);
		record.setAtdPm(LocalDateTime.now().toString().substring(11,19));
		int rows=-1;
		if(row==1){
			//打了卡，修改
			rows=atdBiz.update(record);
		}else{
			//未打卡，插入
			rows=atdBiz.insert(record);
		}
		return rows;
	}
	
}
